package com.weishaoying.rws.mult;

public class DataSourceTypeManager {

    // ThreadLocal类是实现线程安全的关键，因为数据操作大部分都是并发执行，所以必须要考虑线程安全
    private static final ThreadLocal<DataSources> dataSourceTypes = new ThreadLocal<DataSources>() {

        @Override
        protected DataSources initialValue() {
            return DataSources.READ;
        }
    };

    public static DataSources get() {
        return dataSourceTypes.get();
    }

    public static void set(DataSources dataSourceType) {
        dataSourceTypes.set(dataSourceType);
    }

    public static void reset() {
        dataSourceTypes.set(DataSources.READ);
    }

}